package edu.java.homework.hw03.ipj05;

import java.util.Arrays;
import java.util.Scanner;

public class Exercise01done {

    /**
     * Задача 1. Да се напише фрагмент от програма, с помощта на който се
     * инициализира масив, чийто елементи са цели числа.
     * 
     * @param args
     */
    public static void main(String[] args) {
	// 

	Scanner input = new Scanner(System.in);

	int length = -1;
	do {
	    try {
		System.out.print("Enter array's dimention: ");
		length = input.nextInt();
	    } catch (IllegalStateException e) {
		length = -1;
	    }
	    length = (length < 1) ? -1 : length;
	} while (length < 1);
	// TODO: do NOT trust to the user - always verify the data coming from
	// him
	// TODO: what's up if he passes you negative length, for example -1

	int[] intArr = new int[length];
	System.out.println("Enter the array's elements.");
	for (int index = 0; index < intArr.length; index++) {
	    System.out.printf("array[%d]= ", index);
	    intArr[index] = input.nextInt();
	}

	System.out.println();
	System.out.println("Result:");
	System.out.println(Arrays.toString(intArr));

    }
    // TODO: create a method which reads the user input and verifies whether it
    // is correct. If not - the method should notify the user for the incorrect
    // input and ask him to enter the data again, but this time correctly

    // TODO: create static method, which executes the initialization, using the
    // method which reads the user input

}
